<template>
  <div>
    <el-cascader
      :value="value"
      class="inputW"
      size="mini"
      :props="props"
      :options="treeData"
      separator="-"
      @change="changeValue"
    />
  </div>
</template>

<script>
import { getDepartListApi } from '@/api/department'
import { transList2Tree } from '@/utils'
export default {
  components: {},
  props: {
    value: Number,
    default: null
  },
  data() {
    return {
      treeData: [],
      props: {
        label: 'name',
        value: 'id',
        checkStrictly: true
      }
    }
  },

  computed: {},

  created() {
    this.getTreeData()
  },

  methods: {
    async getTreeData() {
      const res = await getDepartListApi()
      // console.log(res)
      this.treeData = transList2Tree(res, 0)
    },
    changeValue(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1]) // 将最后一位的id取出来 传出去
      } else {
        this.$emit('input', null) // 如果长度为0 说明值为空
      }
    }
  }
}

</script>
<style  scoped lang="scss">
</style>
